function [ output ] = F_Bayes_Normal( omega_1,omega_2,P_omega1)
% para:this function is used to classify two classes, each cloumn of
%       omega_1/omega_2 is a sample of class 1/2, P_omega1/P_omega2 
%       is the prior probability of class 1/2.
% output:output is a struct, the answer is X^T*A*X+B*X+C=0;
% author:lijiguo
% data:20160924

%size
omega_1_size=size(omega_1);
omega_2_size=size(omega_2);
%check the dim of omega_1 and omega_2
if omega_1_size(1)~=omega_2_size(1)
    disp('dim of the vector in omega_1 is different with that in omega_2 ');
    return;
end
if ~(P_omega1>0 && P_omega1<1)
    disp('P_omega1 is illegal ');
    return;
end
%mean
mean_1=mean(omega_1,2);
mean_2=mean(omega_2,2);
%cov
omega_1_mean_1_sub=omega_1-repmat(mean_1,1,omega_1_size(2));
omega_2_mean_2_sub=omega_2-repmat(mean_2,1,omega_2_size(2));

sub_1_size=size(omega_1_mean_1_sub);
sub_2_size=size(omega_2_mean_2_sub);
for i=1:sub_1_size(2)
    cov_1(:,:,i)=omega_1_mean_1_sub(:,i)*omega_1_mean_1_sub(:,i).';
end

for i=1:sub_2_size(2)
    cov_2(:,:,i)=omega_2_mean_2_sub(:,i)*omega_2_mean_2_sub(:,i).';
end

C_1=mean(cov_1,3);
C_2=mean(cov_2,3);

C_1_inv=inv(C_1);
C_2_inv=inv(C_2);
%output
output.A=C_1_inv-C_2_inv;
output.B=-( (mean_1.'*C_1_inv-mean_2.'*C_2_inv) + (C_1_inv*mean_1-C_2_inv*mean_2).' );
output.C=mean_1.'*C_1_inv*mean_1-mean_2.'*C_2_inv*mean_2+2*log(P_omega1/(1-P_omega1))+log(det(C_1)/det(C_2));
%normal the coefficient
%find a number which is not zero
flag=(0==1);
divisor=1;
o_A_size=output.A;
for i=1:o_A_size(2)
    for j=1:o_A_size(1)
        if ~(output.A(i,j) == 0)
            flag=1;
            divisor=output.A(i,j);
        end
    end
end
if ~flag
    o_B_size=size(output.B);
    for i=1:o_B_size(1)
        if ~(output.B(i)==0)
            falg=1;
            divisor=output.B(i);
        end
    end
end
output.A=output.A./divisor;
output.B=output.B./divisor;
output.C=output.C./divisor;
end

